package com.shuang.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.shuang.common.CodeRandomUtil;
import com.shuang.service.CommonService;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
@Service("commonService")
public class CommonServiceImpl implements CommonService {
	//通过配置文件注入值
	@Value("${ALDY_URL}")
    private String ALDY_URL;
	@Value("${ALDY_APPKEY}")
    private String ALDY_APPKEY;
	@Value("${ALDY_SECRET}")
    private String ALDY_SECRET;
	@Value("${ALDY_DXMB_NAME}")
    private String ALDY_DXMB_NAME;
	@Value("${ALDY_DXMB_CODE}")
    private String ALDY_DXMB_CODE;
	@Value("${ALDY_USERNAME}")
    private String ALDY_USERNAME;
	
	@Override
	public Map<String, Object> getPhoneCode(String phone) {
		TaobaoClient client = new DefaultTaobaoClient(ALDY_URL, ALDY_APPKEY, ALDY_SECRET);
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
		req.setExtend("");
		req.setSmsType("normal");
		req.setSmsFreeSignName(ALDY_DXMB_NAME);
		
		String code =CodeRandomUtil.sixCodeNoRepeat();
		
		System.out.println(code);
		
		req.setSmsParamString("{name:'"+ALDY_USERNAME+"',code:'"+code+"'}");
		req.setRecNum(phone);
		req.setSmsTemplateCode(ALDY_DXMB_CODE);
		AlibabaAliqinFcSmsNumSendResponse rsp = null;
		/*try {
			rsp = client.execute(req);
		} catch (ApiException e) {
			e.printStackTrace();
		}*/
	/*	这个输出可以是返回的数据格式，其中成功的就是输出
		{"alibaba_aliqin_fc_sms_num_send_response":{"result":{"err_code":"0","model":"104487837066^1106164554926","success":true},"request_id":"3b4uh04u7m34"}}
*/
		//System.out.println(rsp.getBody());
		Map<String ,Object> map=new HashMap<String, Object>();
		/*if(rsp.getErrorCode()==null){*/
			map.put("status", 1);
			map.put("code",code);
		/*}else{
			map.put("status", 0);
		}*/
		return map;
	}

	
}
